<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1><span>5</span>秒后跳转百度</h1>
		<script>
			let spanbox=document.querySelector("span");
			let num=+spanbox.innerHTML;
			//周期性定时器
			let timer=null;
			timer=setInterval(function(){
				num--;
				if(num<=1){//停止定时器，跳转百度
					clearInterval(timer);
					timer=null;
					//跳转百度 BOM location（专门操作浏览器url)
					//location.href="http://www.baidu.com";
					
					//window.open 打开新窗口
					window.open("http://www.baidu.com")
					//window.open 打开新窗口(替换当前页面)
					//window.open("http://www.baidu.com","_self")
				}
				spanbox.innerHTML=num;
			},1000)
		</script>
	</body>
</html>
